package com.jinzhi.jzweb.controller;


import java.util.*;

import com.jinzhi.jzapi.domain.UserDO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.baomidou.mybatisplus.plugins.Page;
import com.jinzhi.common.annotation.Log;
import com.jinzhi.common.base.BaseController;
import com.jinzhi.jzweb.domain.JazOrderLogDO;
import com.jinzhi.jzweb.service.JazOrderLogService;
import com.jinzhi.common.utils.Result;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 
 * <pre>
 * 订单日志表
 * </pre>
 * <small> 2024-07-29 08:50:29 | Long</small>
 */
@Controller
@RequestMapping("/jzweb/jazOrderLog")
public class JazOrderLogController extends BaseController {
	@Autowired
	private JazOrderLogService jazOrderLogService;
	
	@GetMapping()
	@RequiresPermissions("jzweb:jazOrderLog:jazOrderLog")
	String JazOrderLog(){
	    return "jzweb/jazOrderLog/jazOrderLog";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("jzweb:jazOrderLog:jazOrderLog")
	public Result<Page<JazOrderLogDO>> list(JazOrderLogDO jazOrderLogDTO){
		// 查询列表数据
		Page<JazOrderLogDO> page = jazOrderLogService.selectPage(getPage(JazOrderLogDO.class),
					jazOrderLogService.convertToEntityWrapper().orderBy("id", false));
		List list = new ArrayList();
		for (int i = 0; i < page.getRecords().size(); i++) {
				JazOrderLogDO obj = (JazOrderLogDO) page.getRecords().get(i);
			list.add(obj);
		}
		page.setRecords(list);
        return Result.ok(page);
	}
	
	@GetMapping("/add")
	@RequiresPermissions("jzweb:jazOrderLog:add")
	String add(){
	    return "jzweb/jazOrderLog/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("jzweb:jazOrderLog:edit")
	String edit(@PathVariable("id") Long id,Model model){
		JazOrderLogDO jazOrderLog = jazOrderLogService.selectById(id);
		model.addAttribute("jazOrderLog", jazOrderLog);
	    return "jzweb/jazOrderLog/edit";
	}


	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("jzweb:jazOrderLog:add")
	public Result<String> save( JazOrderLogDO jazOrderLog){
		jazOrderLogService.insert(jazOrderLog);
        return Result.ok();
	}
	

	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("jzweb:jazOrderLog:edit")
	public Result<String>  update( JazOrderLogDO jazOrderLog){
		boolean update = jazOrderLogService.updateById(jazOrderLog);
		return update ? Result.ok() : Result.fail();
	}
	
	@Log(value = "删除订单日志表",sysModule = 5,operationType = 2)
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("jzweb:jazOrderLog:remove")
	public Result<String>  remove( Long id){
		jazOrderLogService.deleteById(id);
        return Result.ok();
	}
	
	@Log(value = "批量删除订单日志表",sysModule = 5,operationType = 2)
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("jzweb:jazOrderLog:batchRemove")
	public Result<String>  remove(@RequestParam("ids[]") Long[] ids){
		jazOrderLogService.deleteBatchIds(Arrays.asList(ids));
		return Result.ok();
	}


	@ResponseBody
	@PostMapping("/saveOrderLog")
	public Result<String> saveOrderLog(HttpServletRequest request, @RequestBody JazOrderLogDO jazOrderLogDO){
		UserDO user = this.getUser();

		jazOrderLogService.saveOrderLog(jazOrderLogDO,user, request);
		return Result.ok();
	}

	/**
	 *  分页订单日志查询
	 * @return
	 */
	@GetMapping("/selOrderLogList")
	@ResponseBody
	public Result<Page<JazOrderLogDO>> selOrderLogList(JazOrderLogDO jazOrderLogDO)  {

		return jazOrderLogService.selOrderLogList(jazOrderLogDO);
	}

	/**
	 * 导出日志
	 * @param response
	 * @param logDTO
	 */
	@Log(value = "导出订单日志",sysModule = 12,operationType = 4)
	@ResponseBody
	@GetMapping("/download")
	public void downloadImportTemplate(HttpServletResponse response, JazOrderLogDO logDTO) {
		jazOrderLogService.downloadImportTemplate(response, logDTO);
	}
}
